package cn.iocoder.yudao.module.ai.tool.function;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonClassDescription;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import lombok.Data;
import org.springframework.ai.chat.model.ToolContext;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
import java.util.function.BiFunction;

/**
 * 工具：工单详情查询
 * <p>
 * 同时，也是展示 ToolContext 上下文的使用
 *
 * @author Ren
 */
@Component("work_sheet_detail_query")
public class WorkSheetDetailQueryToolFunction
        implements BiFunction<WorkSheetDetailQueryToolFunction.Request, ToolContext, String> {


    @Data
    @JsonClassDescription("工单详情信息查询")
    public static class Request {

        /**
         * 工单号
         */
        @JsonProperty(required = true, value = "workTickets")
        @JsonPropertyDescription("工单号，必填字段")
        private String workTickets;


    }

//    @Data
//    @AllArgsConstructor
//    @NoArgsConstructor
//    public static class Response {
//
//    }

    @Override
    public String apply(Request request, ToolContext toolContext) {
        Map<String, Object> map = new HashMap<>();
        map.put("workTickets", request.getWorkTickets());
        String result = HttpUtil.createPost("http://192.168.1.168:38090/admin-api/storeroom/work-sheets/createTickets")
                .addHeaders(Map.of("Authorization", "aee80760f75c41c4866ecb9ef418c475"))
                .body(JSONObject.toJSONString(map))
                .execute()
                .body();
        return result;
    }

}
